package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 游记
 */
@Getter@Setter@ToString
public class Travel extends BaseDomain {
    public static final Integer STATE_COMMON = 0;//草稿
    public static final Integer STATE_AUDIT = 1;//待审核
    public static final Integer STATE_RELEASE = 2;//发布
    public static final Integer STATE_REJECT = -1;//拒绝

    private String title;//标题

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;//出行时间

    private String perExpends;//人均费用

    private Integer days;//出行天数

    private Integer person;//参与人物

    private User author;//作者

    private Date createTime;//创建时间

    private Date releaseTime;//发布时间

    private Boolean isPublic = false;//是否公开

    private Region place;//旅游地点

    private String coverUrl;//封面图片

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date lastUpdateTime;//最后更新时间

    private Integer state = STATE_COMMON;//状态

    private TravelContent travelContent;//游记内容

    public String getStateName(){
        String stateName = "草稿";
        if (state == Travel.STATE_AUDIT) {
            stateName = "待审核";
        }else if (state == Travel.STATE_RELEASE) {
            stateName = "发布";
        }else if (state == Travel.STATE_REJECT) {
            stateName = "拒绝";
        }
        return stateName;
    }

    public String getPersonName(){
        String personName = "一个人的旅行";
        if (2 == person) {
            personName = "和父母";
        }else if (3 == person) {
            personName = "和朋友";
        }else if (4 == person) {
            personName = "和同事";
        }else if (5 == person) {
            personName = "和爱人";
        }else if (6 == person) {
            personName = "和其他";
        }
        return personName;
    }

    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("title",title);
        map.put("travelId",id);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }
}